#pragma once

#include"LogInWindow.h"
#include"ChangePasswordWindow.h"
#include"BusStopDistribution.h"
#include"EditDataBasa.h"

namespace mpk_internal_system {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		LogInWindow ^ logWin;
		ChangePasswordWindow ^ changeWin;
		BusStopDistribution ^ busStopDistrWin;
		EditDataBasa ^ EditWin;

		bool loggerTimer, changePswdTimer, BusStopDistrTimer, EditTimer;
	private: System::Windows::Forms::Button^  editDataBasa;
	public: 

	private: System::Windows::Forms::Button^  busStopDistribution;//??
	public: 
		Form1(void)
		{
			InitializeComponent();
			
			changeWin = gcnew ChangePasswordWindow;
			busStopDistrWin = gcnew BusStopDistribution;
			logWin = gcnew LogInWindow;
			EditWin = gcnew EditDataBasa;

			logWin->Show();

			logWin->logger = gcnew sLogIn();

			loggerTimer = true;
			changePswdTimer = false;
			BusStopDistrTimer = false;
			EditTimer = false;
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Timer^  timer1;
	private: System::Windows::Forms::GroupBox^  Menu;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  change_pswd;

	private: System::Windows::Forms::Button^  logout;
	protected: 
	private: System::ComponentModel::IContainer^  components;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->Menu = (gcnew System::Windows::Forms::GroupBox());
			this->editDataBasa = (gcnew System::Windows::Forms::Button());
			this->busStopDistribution = (gcnew System::Windows::Forms::Button());
			this->logout = (gcnew System::Windows::Forms::Button());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->change_pswd = (gcnew System::Windows::Forms::Button());
			this->Menu->SuspendLayout();
			this->SuspendLayout();
			// 
			// timer1
			// 
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
			// 
			// Menu
			// 
			this->Menu->Controls->Add(this->editDataBasa);
			this->Menu->Controls->Add(this->busStopDistribution);
			this->Menu->Controls->Add(this->logout);
			this->Menu->Controls->Add(this->label2);
			this->Menu->Controls->Add(this->label1);
			this->Menu->Controls->Add(this->change_pswd);
			this->Menu->Location = System::Drawing::Point(12, 12);
			this->Menu->Name = L"Menu";
			this->Menu->Size = System::Drawing::Size(260, 238);
			this->Menu->TabIndex = 0;
			this->Menu->TabStop = false;
			this->Menu->Text = L"Menu";
			// 
			// editDataBasa
			// 
			this->editDataBasa->Location = System::Drawing::Point(6, 77);
			this->editDataBasa->Name = L"editDataBasa";
			this->editDataBasa->Size = System::Drawing::Size(109, 23);
			this->editDataBasa->TabIndex = 5;
			this->editDataBasa->Text = L"Edit Data Base";
			this->editDataBasa->UseVisualStyleBackColor = true;
			this->editDataBasa->Click += gcnew System::EventHandler(this, &Form1::editDataBasa_Click);
			// 
			// busStopDistribution
			// 
			this->busStopDistribution->Location = System::Drawing::Point(6, 48);
			this->busStopDistribution->Name = L"busStopDistribution";
			this->busStopDistribution->Size = System::Drawing::Size(109, 23);
			this->busStopDistribution->TabIndex = 4;
			this->busStopDistribution->Text = L"Bus stop distribution";
			this->busStopDistribution->UseVisualStyleBackColor = true;
			this->busStopDistribution->Click += gcnew System::EventHandler(this, &Form1::busStopDistribution_Click);
			// 
			// logout
			// 
			this->logout->Location = System::Drawing::Point(179, 62);
			this->logout->Name = L"logout";
			this->logout->Size = System::Drawing::Size(75, 23);
			this->logout->TabIndex = 3;
			this->logout->Text = L"Log Out";
			this->logout->UseVisualStyleBackColor = true;
			this->logout->Click += gcnew System::EventHandler(this, &Form1::logout_Click);
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(197, 46);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(35, 13);
			this->label2->TabIndex = 2;
			this->label2->Text = L"label2";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(176, 24);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(78, 13);
			this->label1->TabIndex = 1;
			this->label1->Text = L"You logged as:";
			// 
			// change_pswd
			// 
			this->change_pswd->Location = System::Drawing::Point(6, 19);
			this->change_pswd->Name = L"change_pswd";
			this->change_pswd->Size = System::Drawing::Size(109, 23);
			this->change_pswd->TabIndex = 0;
			this->change_pswd->Text = L"Change password";
			this->change_pswd->UseVisualStyleBackColor = true;
			this->change_pswd->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->Menu);
			this->Name = L"Form1";
			this->Text = L"Menu";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->Menu->ResumeLayout(false);
			this->Menu->PerformLayout();
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				 this->Visible = false;
				 timer1->Start();
			 }

	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
				 if(loggerTimer){
					 this->Visible = false;
					 if(logWin->succeed_logged == true){
						logWin->Close();
						this->Visible = true;

						//Who logged?
						label2->Text = logWin->logger->user;
						if(logWin->logger->user == "user")	change_pswd->Enabled = false;
						else change_pswd->Enabled = true;

						if(logWin->logger->user == "admin")	editDataBasa->Enabled = true;
						else editDataBasa->Enabled = false;

						loggerTimer = false;
						timer1->Stop();
					 }
				 }
				 else if(changePswdTimer){
					 this->Visible = false;
					 if(changeWin->succeed_changed){
						changeWin->Close();
						this->Visible = true;

						changePswdTimer = false;
						changeWin->succeed_changed = false;
						timer1->Stop();
					 }
				 }
				 else if(BusStopDistrTimer){
					 this->Visible = false;
					 if(busStopDistrWin->succeed_distr){
						busStopDistrWin->Close();
						this->Visible = true;

						BusStopDistrTimer = false;
						busStopDistrWin->succeed_distr = false;
						timer1->Stop();
					 }
				 }
				 else if(EditTimer){
					 this->Visible = false;
					 if(EditWin->succeed_edit){
						EditWin->Close();
						this->Visible = true;

						EditTimer = false;
						EditWin->succeed_edit = false;
						timer1->Stop();
					 }
				 }
				 else this->Visible = false;
			 }
	private: System::Void logout_Click(System::Object^  sender, System::EventArgs^  e) {
				 this->Visible = false;
				 logWin->succeed_logged = false;

				 logWin = gcnew LogInWindow;
				 logWin->Show();

				 loggerTimer = true;
				 timer1->Start();
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 this->Visible = false;
				 changePswdTimer = true;
				 changeWin->succeed_changed = false;

				 changeWin = gcnew ChangePasswordWindow;
				 changeWin->Show();

				 timer1->Start();
			 }
	private: System::Void busStopDistribution_Click(System::Object^  sender, System::EventArgs^  e) {
				 this->Visible = false;
				 BusStopDistrTimer = true;
				 busStopDistrWin->succeed_distr = false;

				 busStopDistrWin = gcnew BusStopDistribution;
				 busStopDistrWin->Show();

				 timer1->Start();
			 }
	private: System::Void editDataBasa_Click(System::Object^  sender, System::EventArgs^  e) {
				this->Visible = false;
				EditTimer = true;
				EditWin->succeed_edit = false;

				EditWin = gcnew EditDataBasa;
				EditWin->Show();

				timer1->Start();
			 }
	};
}

